﻿namespace OpenLS.Drawing.UI.Internals
{
    internal class LineStyleFormatter
    {
        private readonly IShape _model;

        public LineStyleFormatter(IShape model)
        {
            _model = model;
        }
        ShapeProperties EnsureShapeProperties()
        {
            if (_model.ShapeProperties == null)
                _model.ShapeProperties = new ShapeProperties();
            return _model.ShapeProperties;
        }
        LineProperties EnsureLineProperties()
        {
            if (EnsureShapeProperties().LineProperties == null)
                EnsureShapeProperties().LineProperties = new LineProperties();
            return EnsureShapeProperties().LineProperties;
        }
        public LineCap LineCap
        {
            get { return EnsureLineProperties().LineCap; }
            set { EnsureLineProperties().LineCap = value; }
        }

        public PresetLineDashValue DashArray
        {
            get
            {
                PresetLineDashProperties v = EnsureLineProperties().LineDashProperties as PresetLineDashProperties;
                if (v != null)
                    return v.Value;
                return PresetLineDashValue.Solid;
            }

            set { EnsureLineProperties().LineDashProperties = new PresetLineDashProperties(value); }
        }

        public double? Width
        {
            get { return EnsureLineProperties().Width; }
            set { EnsureLineProperties().Width = value; }
        }
    }
}